import * as THREE from "three";
import { CSS3DObject, CSS3DRenderer, EffectComposer, FilmPass, FXAAShader, ShaderPass } from "three/examples/jsm/Addons.js";
import { RenderPass } from "three/examples/jsm/Addons.js";
import { BloomPass } from "three/examples/jsm/Addons.js";
import { PointerLockControls } from "three/examples/jsm/controls/PointerLockControls.js";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
// import { createLabelzhj, createLabel7k, createLabelkbj, createLabells7k, labelRenderer } from './CSS2D/CSS2DZJ';//提取罐标签组
import GUI from "three/examples/jsm/libs/lil-gui.module.min.js"; //引入GUI组件库
import {  createLabelads,createDashboardPanel,  labelRenderer  } from './CSS3D/CSS3D';
import model from "./3Dmodel/model1";
import modelmountain from "./3Dmodel/modelMountain";

// import worker1 from "./3Dmodel/worker1";
// import worker2 from "./3Dmodel/worker2";
import { reactive } from "vue";
// import { createHelloWorld3DObject, } from "./components/Dom/HellowDom";
// import { createCanvasSvg3DObject } from "./components/Dom/Canvas.svg";

// import { act } from "./websocket";
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100000);
// 假设有不同的摄像机位置-1840, -122, 1380 1550, -200, 1185
const cameraPositions = {
  Start: { position: { x: 500, y: 1600, z: 2600 }, lookAt: { x: 0, y: 0, z: 0 } },
  Ads: { position: { x: 0, y: 10, z: 20 }, lookAt: { x: 0, y: 0, z: 0 } },
  Tds: { position: { x: 500, y: 600, z: 200 }, lookAt: { x: 500, y: 200, z: -400 } },
  T3_T4: { position: { x: 600, y: 1000, z: 550 }, lookAt: { x: 600, y: 200, z: 550 } },
  T7K_10K: { position: { x: -1300, y: 800, z: 500 }, lookAt: { x: -1300, y: 200, z: 0 } },
  Scale: { position: { x: 1050, y: 200, z: 1900 }, lookAt: { x: 1550, y: -200, z: 1900 } },
};
camera.position.set(cameraPositions.Start.position.x, cameraPositions.Start.position.y, cameraPositions.Start.position.z);
camera.lookAt(cameraPositions.Start.lookAt.x, cameraPositions.Start.lookAt.y, cameraPositions.Start.lookAt.z);
// 创建一个控制摄像机位置和视角目标的对象
const cameraControl = {
  cameraPosition: "Start" // 初始选择项是 "A"
};


// 参数控制
export const T7K = {
  T7K_PwsNo:"null",
  T7K_MaterialName:"null",
  T7K_BatchNo:"null",
  T7K_PlannedQty:"null",
  T7K_WEGT:0,
  T7K_FrequencySetValue:0,
  T7K_FrequencyActualValue:0,
  T7K_RSpeedActualValue:0,
  T7K_RSpeedSetValue:0,
  T7K_FrequencyConverter_Running: false,
  T7K_CurrentActualValue:0,
  T7K_AccRunTime:0,
  T7K_ConverterErrorCode:0,
  T7K_ConverterFaultCode:0,
}
export const T10K = {
  T10K_PwsNo:"null",
  T10K_MaterialName:"null",
  T10K_BatchNo:"null",
  T10K_PlannedQty:"null",
  T10K_WEGT:0,
  T10K_FrequencySetValue:0,
  T10K_FrequencyActualValue:0,
  T10K_RSpeedActualValue:0,
  T10K_RSpeedSetValue:0,
  T10K_FrequencyConverter_Running: false,
  T10K_CurrentActualValue:0,
  T10K_AccRunTime:0,
  T10K_ConverterErrorCode:0,
  T10K_ConverterFaultCode:0,
}
export const T3 = {
  T3_PwsNo:"null",
  T3_MaterialName:"null",
  T3_BatchNo:"null",
  T3_PlannedQty:"null",
  T3_WEGT:0,
  T3_FrequencySetValue:0,
  T3_FrequencyActualValue:0,
  T3_RSpeedActualValue:0,
  T3_RSpeedSetValue:0,
  T3_FrequencyConverter_Running: false,
  T3_CurrentActualValue:0,
  T3_AccRunTime:0,
  T3_ConverterErrorCode:0,
  T3_ConverterFaultCode:0,
}
export const T4 = {
  T4_PwsNo:"null",
  T4_MaterialName:"null",
  T4_BatchNo:"null",
  T4_PlannedQty:"null",
  T4_WEGT:0,
  T4_FrequencySetValue:0,
  T4_FrequencyActualValue:0,
  T4_RSpeedActualValue:0,
  T4_RSpeedSetValue:0,
  T4_FrequencyConverter_Running: false,
  T4_CurrentActualValue:0,
  T4_AccRunTime:0,
  T4_ConverterErrorCode:0,
  T4_ConverterFaultCode:0,
}
export const mes = {
  mes_plc_status:0,
}
export const ADS = reactive({
  ADS_SCALE1_REALWGHT:0,
  ADS_D22203_L:0,
  TankNo:0,
  IngreName:"null",
  IngreCode:"null",
})
export const ads = {
  ads_plc_status:0,
}
export const scale = {
  scale_27:0,
  scale_28:0,
  scale_29:0,
  scale_30:0,
  scale_31:0,
  scale_32:0,
  scale_33:0,
  scale_34:0,
}
export const tds = {
  tds_plc_status:0, 
  tds_premix_temperature:0,//预混温度设定
  tds_motor_temp:0,//电机温度
  tds_actual_current:0,
  tds_actual_power:0,
  tds_speed_set:0,//速度设定
  tds_time_set:0,//时间设定
  tds_mixspeed_set:0,
  tds_target_set:0,
  tds_dischargespeed_set:0,
  tds_draintime_set:0,
}

export const test = {
  ZBJvisible: false,
  run: true,
  WBvisible: true,
  NBvisible: true,
};
export const Visible = {
  LTK:true,
};
// 创建 GUI 控制器
const gui = new GUI(); // 渲染一个控制器
gui.domElement.style.right = "0px"; // 右边距
gui.domElement.style.width = "300px"; // 宽度

// 创建下拉框选择器
const positionControl = gui.add(cameraControl, "cameraPosition", ["Start", "Ads", "Tds", "T3_T4", "T7K_10K", "Scale"])
  .name("选择摄像机位置")
  .onChange((value) => {
    // 当选择改变时，更新摄像机的位置和视角目标
    const position = cameraPositions[value];
    camera.position.set(position.position.x, position.position.y, position.position.z);
    camera.lookAt(position.lookAt.x, position.lookAt.y, position.lookAt.z);
    // 关键：同步更新控制器的目标点
    orbitControls.target.set(
      position.lookAt.x,
      position.lookAt.y,
      position.lookAt.z
    );
  });

const mad = gui.addFolder("总信息面板控制");
  mad
  .add(test, "run")
  .name(" 信息面板")
  .onChange((value: boolean) => {
     //toggleLabelVisibility(label1bzj,value)
    test.run = value; // 切换布尔值
  });

  mad
  .add(Visible, "LTK")
  .name("立体库显隐")
  .onChange((value: boolean) => {
    Visible.LTK = value; // 切换布尔值
  });

export const RUN = {
  ads01run:false,
  ads02run:false,
  ads03run:false,
  ads04run:false,
  ads05run:false,
  ads06run:false,
  ads07run:false,
  ads08run:false,
  ads09run:false,
  ads10run:false,
  ads11run:false,
  ads12run:false,
  ads13run:false,
  ads14run:false,
  ads15run:false,
  ads16run:false,
  ads17run:false,
  ads18run:false,
  ads19run:false,
  ads20run:false,
  ads21run:false,
};

export const TQ = {
  //提取储罐
  TQG2: "null",
  TQG2_upperTemp: 0,
  TQG2_lowerTemp: 0,
  TQG2_LJJL: 0,
  TQG2_BCJL: 0,
  //提取储罐
  TQCG2_tqliquid: 0,
  //单效浓缩
  DXNS2_liquid: 0,
  DXNS2_dxTemp: 0,
  //冷藏
  LC84_Temp: 0,
  LC84_time: 0,
  LC84_timemin: 0,
};



// 渲染函数
function render() {
  renderer.render(scene, camera); // 渲染 Three.js 场景
  labelRenderer.render(scene, camera); // 渲染 CSS2DObject 标签
}

// 创建场景
const scene = new THREE.Scene();
scene.background = new THREE.Color('#1c2938'); // 天空蓝
//加载球面贴图#131824
const loader =new THREE.TextureLoader();
const texture =loader.load('/3D/fj3.jpg')
//设置环境贴图映射类型
texture.mapping=THREE.EquirectangularRefractionMapping;
//设置环境贴图和场景
// scene.background=texture;
scene.environment=texture;

const labels: CSS3DObject[] = []; // 修改数组类型为 CSS3DObject

createLabelads(
  'ADS',
  'ADS',
);
createDashboardPanel('dashboard');
function toggleLabelVisibility(label:any, isVisible: boolean) {
  label.visible = isVisible;
}
// 设置定时器，每隔 5 秒调用一次 updateLabels
const refreshInterval = 10000; // 刷新间隔，单位为毫秒
// setInterval(updateLabels, refreshInterval);

//  CSS3DRenderer
// const labelRendererx = new CSS3DRenderer()
labelRenderer.setSize(window.innerWidth, window.innerHeight)
labelRenderer.domElement.style.position = 'absolute'
labelRenderer.domElement.style.top = '0'
labelRenderer.domElement.style.pointerEvents = 'none'
document.body.appendChild(labelRenderer.domElement)

// 添加 HelloWorld 面板


// const panel = createHelloWorld3DObject(
//   new THREE.Vector3(0, 0, 0),
//   // new THREE.Euler(0, Math.PI / 4, 0)
// )
// scene.add(panel)
// panel.scale.set(0.05, 0.05, 0.05)

// const panelCanvasSvg=createCanvasSvg3DObject(
//   new THREE.Vector3(0, 0, 0),
//   undefined, 0
// )
// scene.add(panelCanvasSvg)
// panelCanvasSvg.scale.set(0.05, 0.05, 0.05)







// // 将标签添加到场景中
const modelx = new THREE.Group();
labels.forEach(label => modelx.add(label));
scene.add(modelx);

modelx.position.set(0, 0, 0);

// // 创建地板
// const floorGeometry = new THREE.PlaneGeometry(1000, 1000);
// floorGeometry.rotateX(-Math.PI / 2);
// const floorMaterial = new THREE.MeshLambertMaterial({ color: 0x555555, side: THREE.DoubleSide });
// const floorMesh = new THREE.Mesh(floorGeometry, floorMaterial);
// scene.add(floorMesh);

// 创建相机

// function printCameraPosition(camera: { position: { x: any; y: any; z: any; }; }) {
//   const { x, y, z } = camera.position;
//   console.log(`Camera Position - x: ${x}, y: ${y}, z: ${z}`);
// }
// 创建渲染器
const renderer: any  = new THREE.WebGLRenderer({ antialias: true });
renderer.shadowMap.enabled = true;  // 启用阴影
renderer.physicallyCorrectLights = true;  // 启用物理正确的光照模型

// 创建EffectComposer
const composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
composer.addPass(new BloomPass(1.25, 25, 4.0, ));  // 添加 Bloom 效果
// 添加 FXAA 效果
const fxaaPass = new ShaderPass(FXAAShader);
const pixelRatio = renderer.getPixelRatio();
fxaaPass.material.uniforms['resolution'].value.set(1 / (window.innerWidth * pixelRatio), 1 / (window.innerHeight * pixelRatio));
composer.addPass(fxaaPass);

renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// 添加鼠标控制相机旋转
const controls = new PointerLockControls(camera, document.body);
scene.add(controls.getObject());

// 添加轨道控制器
const orbitControls = new OrbitControls(camera, renderer.domElement);
// orbitControls.enableDamping = true; // 启用阻尼效果
// orbitControls.dampingFactor = 0.05;
orbitControls.enabled = true;
let isDrawing = false;
let currentLine: THREE.Line | null = null;
let currentPoints: THREE.Vector3[] = [];
const drawLines: THREE.Line[] = [];
let drawingEnabled = false; // 默认关闭画笔



// 👇 鼠标按下：左键绘制，右键清除（仅在启用绘制时生效）
window.addEventListener('mousedown', (e) => {
  if (!drawingEnabled) return;

  if (e.button === 0) {
    isDrawing = true;
    startNewLine();
  } else if (e.button === 2) {
    clearDrawings();
  }
});

window.addEventListener('mouseup', (e) => {
  if (!drawingEnabled) return;

  if (e.button === 0) {
    isDrawing = false;
    currentLine = null;
    currentPoints = [];
  }
});

// 👇 鼠标移动时实时更新当前线条
window.addEventListener('mousemove', () => {
  if (!drawingEnabled || !isDrawing || !currentLine) return;
  const point = getCenterDrawPoint();
  currentPoints.push(point);
  updateCurrentLine();
});

// 👇 防止右键菜单弹出
window.addEventListener('contextmenu', (e) => {
  e.preventDefault();
});

function startNewLine() {
  currentPoints = [];
  const geometry = new THREE.BufferGeometry().setFromPoints(currentPoints);
  const material = new THREE.LineBasicMaterial({ color: 0x00ff00, linewidth: 2,depthTest: false  });

  currentLine = new THREE.Line(geometry, material);
  drawLines.push(currentLine);
  scene.add(currentLine);
}

function updateCurrentLine() {
  if (!currentLine) return;
  currentLine.geometry.dispose();
  currentLine.geometry = new THREE.BufferGeometry().setFromPoints(currentPoints);
}

function getCenterDrawPoint(): THREE.Vector3 {
  const dir = new THREE.Vector3();
  camera.getWorldDirection(dir);
  const distance = 2;
  return new THREE.Vector3().copy(camera.position).add(dir.multiplyScalar(distance));
}

function clearDrawings() {
  for (const line of drawLines) {
    scene.remove(line);
    line.geometry.dispose();
    if (line.material instanceof THREE.Material) line.material.dispose();
  }
  drawLines.length = 0;
}
// 👇 添加键盘切换绘制启用状态（按下 D 键）

// 键盘事件监听器
document.addEventListener('keydown', (event) => {
  if (event.shiftKey && event.key === 'F1') {
    drawingEnabled = !drawingEnabled;
    console.log(`画笔已${drawingEnabled ? '启用' : '禁用'}`);
    if (controls.isLocked) {
      controls.unlock();
      camera.position.set(0, 350, 450);
      camera.lookAt(0, 0, 0);

      orbitControls.reset();
      orbitControls.target.set(0, 0, 0);
      orbitControls.update();
    } else {
      controls.lock();
    }
    
  }

  if (event.key === 'Escape') {
    drawingEnabled = false;
    isDrawing = false;
    currentLine = null;
    currentPoints = [];
    console.log('画笔已取消（ESC）');
  }
  
  if (event.shiftKey && event.key === 'F2') {
    isInspecting = !isInspecting;
    if (isInspecting) {
      currentPathIndex = 0;
      document.body.requestPointerLock(); // 锁定鼠标
    } else {
      document.exitPointerLock(); // 退出鼠标锁定
    }
  }
});

// 创建光源
const light = new THREE.AmbientLight(0xffffff, 1);
scene.add(light);

// 创建平行光
// const directionalLight = new THREE.DirectionalLight(0xffffff, 0);
// directionalLight.position.set(5, 10, 5);
// scene.add(directionalLight);

// // 添加 ArrowHelper 显示光源方向
// const arrowDirection = new THREE.Vector3(-1, -1, -1).normalize();
// const arrowOrigin = new THREE.Vector3(200, 400, 200);
// const arrowLength = 500;
// const arrowColor = 0xff1111;
// const arrowHelper = new THREE.ArrowHelper(arrowDirection, arrowOrigin, arrowLength, arrowColor);
// scene.add(arrowHelper);

// 巡检功能参数
const path = [

  new THREE.Vector3(318,50, 90),
  new THREE.Vector3(220,50, 90),
  new THREE.Vector3(90,50, 80),
  new THREE.Vector3(90,50, 220),
  new THREE.Vector3(-270,50, 220),
  new THREE.Vector3(-270,50, -100),
  new THREE.Vector3(-90,50, -100),
  new THREE.Vector3(-90,50, -120),
  new THREE.Vector3(318,50, -120),
  // new THREE.Vector3(175, 160, -140),
  // new THREE.Vector3(595, 160, -140),
  // new THREE.Vector3(175, 160, -140),
  // new THREE.Vector3(-375, 160, -140),
  // new THREE.Vector3(-780, 160, -140),
  // new THREE.Vector3(-780, 160, 340),
  // new THREE.Vector3(-375, 160, 340),

];

let currentPathIndex = 0;
let isInspecting = false;


// 添加外部模型
//动态添加工人
function WorkersAdd(){

}
modelx.add(model);
modelx.add(modelmountain);

// WASD 控制移动的变量
// WASD 控制移动的变量
let moveForward = false;
let moveBackward = false;
let moveLeft = false;
let moveRight = false;
let moveUp = false;
let moveDown = false;

let isLocked = false; // 控制是否启用移动
let movespeed = 10;    // 移动速度

// 键盘事件监听
const onKeyDown = (event) => {
  if (!isLocked) return;
  switch (event.code) {
    case 'KeyW': moveForward = true; break;
    case 'KeyA': moveLeft = true; break;
    case 'KeyS': moveBackward = true; break;
    case 'KeyD': moveRight = true; break;
    case 'Space': moveUp = true; break;
    case 'ControlLeft': moveDown = true; break;
  }
};

const onKeyUp = (event) => {
  if (!isLocked) return;
  switch (event.code) {
    case 'KeyW': moveForward = false; break;
    case 'KeyA': moveLeft = false; break;
    case 'KeyS': moveBackward = false; break;
    case 'KeyD': moveRight = false; break;
    case 'Space': moveUp = false; break;
    case 'ControlLeft': moveDown = false; break;
  }
};

document.addEventListener('keydown', onKeyDown);
document.addEventListener('keyup', onKeyUp);

// 每帧更新的移动函数
function updateCameraMovement() {
  if (!isLocked) return;
  
  const forward = new THREE.Vector3();
  camera.getWorldDirection(forward);

  const right = new THREE.Vector3();
  right.crossVectors(camera.up, forward).normalize();

  const moveDirection = new THREE.Vector3();

  if (moveForward) moveDirection.add(forward);
  if (moveBackward) moveDirection.sub(forward);
  if (moveRight) moveDirection.sub(right);
  if (moveLeft) moveDirection.add(right);
  if (moveUp) moveDirection.y += 2;
  if (moveDown) moveDirection.y -= 2;

  if (moveDirection.length() > 0) {
    moveDirection.normalize().multiplyScalar(movespeed);
    camera.position.add(moveDirection);

    // 限制最低高度为 y = 10
  //   if (camera.position.y < -0) {
  //     camera.position.y = -0;
  //   }
  }
}
// 创建射线投射器
const raycaster = new THREE.Raycaster();

// 检查相机与目标的距离，决定是否显示提示框
// let isHintShown = true; // 提示框是否已显示
// let isDetailBoxShown = false; // 详细信息框是否已显示

// // 按键事件监听器
// document.addEventListener('keydown', (event) => {
//   if (event.key === 'f') {
//     if (isHintShown) {
//       if (isDetailBoxShown) {
//         console.log("111");
//         hideDetailBox();
//         isDetailBoxShown = false;
//       } else {
//         showDetailBox();
//         isDetailBoxShown = true;
//       }
//     }

//   } else if (event.key === 'Escape' && isDetailBoxShown) {
//     hideDetailBox();
//     isDetailBoxShown = false;
//   }

// });

// 检查相机与目标的距离，决定移动速度model
// function checkProximity() {
//   // const tankObject = scene.getObjectByName("Tube050");
//   if (!model) return;

//   const tankPosition = new THREE.Vector3();
//   model.getWorldPosition(tankPosition);

//   const distance = camera.position.distanceTo(tankPosition);

//   if (distance < 200 ) {
//     console.log("小于100")
//   } else if (distance >= 200 ) {
//     console.log("大于100")
//   }
// }



function updateMoveSpeedByView() {
  
  if (!model) return;
  
  const direction = new THREE.Vector3();
  camera.getWorldDirection(direction);

  raycaster.set(camera.position, direction);

  // 只检测 model 内部的物体
  const intersects = raycaster.intersectObject(model, true); // 第二个参数必须是 true，表示递归遍历子对象

  if (intersects.length > 0) {
    const distance = intersects[0].distance;

    // 根据距离调整速度：越近越慢
    if (distance < 10) {
      console.log("小于20--"+distance)
      movespeed = 0.01;
    } else if (distance < 50) {
      console.log("小于50--"+distance)
      movespeed = 0.1;
    } else if (distance < 100) {
      console.log("小于100--"+distance)
      movespeed = 0.2;
    } else if (distance < 200) {
      console.log("小于200--"+distance)
      movespeed = 0.4;
    }else {
      // 没检测到物体，使用默认最大速度
      movespeed = 1;
      console.log("大于200--"+distance)
    }
  } else {
    // 没检测到物体，使用默认最大速度
    movespeed = 0.5;
    console.log("没检测到物体，使用默认最大速度")
  }
}
// 更新函数
function animate() {

// 判断 Vue 页面是否面向摄像机

//判断vue页面与摄像机位置
// const distanceHellow = panel.position.distanceTo(camera.position);
// if (distanceHellow < 50) {
//   panel.element.style.opacity = '1';
//   panel.element.style.pointerEvents = 'none'; // 开启交互
//   panel.element.style.transition = 'opacity 0.5s ease';
// } else {
//   panel.element.style.opacity = '0';
//   panel.element.style.pointerEvents = 'none'; // 禁用交互
// }

// const distanceCanvas = panelCanvasSvg.position.distanceTo(camera.position);
// if (distanceCanvas < 50) {
//   panelCanvasSvg.element.style.opacity = '1';
//   panelCanvasSvg.element.style.pointerEvents = 'none'; // 开启交互
//   panelCanvasSvg.element.style.transition = 'opacity 0.5s ease';
// } else {
//   panelCanvasSvg.element.style.opacity = '0';
//   panelCanvasSvg.element.style.pointerEvents = 'none'; // 禁用交互
// }



//画图判断
  if (isDrawing && currentLine) {
    const newPoint = getCenterDrawPoint();

    // 如果新点距离上一个点大于阈值再添加（避免太密）
    const lastPoint = currentPoints[currentPoints.length - 1];
    if (!lastPoint || lastPoint.distanceTo(newPoint) > 0.05) {
      currentPoints.push(newPoint);
      updateCurrentLine();
    }
  }

  requestAnimationFrame(animate);
  // updateCameraDirection();
  composer.render();  // 使用 composer 渲染
  // checkProximity();
  //巡检
  if (isInspecting) {
    const target = path[currentPathIndex];
    const direction = target.clone().sub(camera.position).normalize();
    const distance = camera.position.distanceTo(target);

    if (distance > 5) {
      camera.position.add(direction.multiplyScalar(2)); // 按速度移动
    } else {
      currentPathIndex = (currentPathIndex + 1) % path.length; // 继续下一个目标点
    }
  }
  // 更新摄像头朝向
  const targetDirection = new THREE.Vector3();
  controls.getDirection(targetDirection);
  camera.lookAt(camera.position.clone().add(targetDirection));

  scene.traverse((child) => {
    if (child instanceof THREE.Mesh) {
      const body = child.userData.physicsBody;
      if (body !== undefined) {
        child.position.copy(body.position);
        child.quaternion.copy(body.quaternion);
      }
    }
  });
  // checkProximity();
  // 检查标签是否被遮挡
  updateMoveSpeedByView();
  updateCameraMovement();
  
  renderer.render(scene, camera);
  labelRenderer.render(scene, camera);
}

// 监听 PointerLockControls 的锁定和解锁事件
controls.addEventListener('lock', () => {
  isLocked = true;
  orbitControls.enabled = false;
  console.log('PointerLockControls locked');
});

controls.addEventListener('unlock', () => {
  isLocked = false;
  orbitControls.enabled = true;
  console.log('PointerLockControls unlocked, orbitControls.enabled:', orbitControls.enabled);
});

// 开始动画
animate();

// 调整窗口大小时更新渲染器
window.addEventListener('resize', () => {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
  labelRenderer.setSize(window.innerWidth, window.innerHeight);
});

export { renderer, scene, camera }; // 确保导出这些变量
